package dbu;

import java.sql.SQLException;

import dbu.jdbc.JdbcResultSet;
import dbu.sql.SqlCommand;

public class Dbu {

	public static JdbcResultSet getResult(SqlCommand sqlCmd) throws DbuException, SQLException {
		DbFile dbfile = DbPool.getDbfile(sqlCmd.getTableName().toLowerCase());
		Data data = dbfile.find(sqlCmd.getQuery());
		JdbcResultSet resultSet = new JdbcResultSet(data);
		return resultSet;
	}

	public static int delete(SqlCommand sqlCmd) {
		DbFile dbfile = DbPool.getDbfile(sqlCmd.getTableName().toLowerCase());
		int result = dbfile.delete(sqlCmd);
		return result;
	}

	public static int update(SqlCommand sqlCmd) {
		DbFile dbfile = DbPool.getDbfile(sqlCmd.getTableName().toLowerCase());
		int result = dbfile.update(sqlCmd);
		return result;
	}

	public static int insert(SqlCommand sqlCmd) {
		DbFile dbfile = DbPool.getDbfile(sqlCmd.getTableName().toLowerCase());
		int result = dbfile.insert(sqlCmd);
		return result;
	}
}
